﻿<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
	<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
	<title>结算-PHPMall</title>
	<meta name="keywords" content="结算-PHPMall"/>
	<meta name="description" content="结算-PHPMall"/>
	<link rel="stylesheet" href="/static/user/css/base.css" />
	<link rel="stylesheet" href="/static/user/css/cart.css" />
	<link rel="stylesheet" href="/static/layui/css/layui.css" />
	<script src="/static/user/js/jquery-2.1.4.min.js"></script>
	<script src="/static/user/js/jquery-migrate-1.2.1.min.js"></script>
	<script src="/static/layer/layer.js"></script>

</head>
<body>
<div class="com-top-nav w">
	<div class="wcp-wrap">

	</div>
</div>
<!--头部-->
{include file='index@public/header'}
<div class="layui-container">
	<div style="font-size: 18px;margin-top: 2em;margin-bottom: 1em">结算</div>
	<div class="layui-row">
		<div class="layui-card">
			<div class="layui-card-header">收获地址</div>
			<div class="layui-card-body">
				{if $is_add !=0}
				{volist name="userAddress" id="vo_userAddress"}
					<input type="radio" id="address" name="address" checked value="{$vo_userAddress.id}" title="{$vo_userAddress.detailed}">&nbsp;({$vo_userAddress.name}){$vo_userAddress.detailed}-{$vo_userAddress.province}<br><hr>
					<input type="hidden" value="1" id="address_is">
				{/volist}
				{else}
				<a href="{:url('user/user/addAddress')}" style="color:red;">去增加收获地址</a>
				<input type="hidden" value="0" id="address_is">
				{/if}
			</div>
		</div>
		<div class="layui-card">
			<div class="layui-card-header">货运方式</div>
			<div class="layui-card-body">
				<select name="shipping_name" id="shipping_name" class="second-level" style="width: 200px;">
					<option value="EMSS">EMSS</option>
				</select>
			</div>
		</div>
		<div class="layui-card">
			<div class="layui-card-header">订单详情</div>
			<div class="layui-card-body">
				<div class="w_cart_inner">
					<table class="w_cart_table">
						<thead>
						<tr>
							<td>商品编号</td>
							<td>商品图片</td>
							<td style="text-align: left">商品信息</td>
							<td>单价</td>
							<td>商品数量</td>
							<td></td>
						</tr>
						</thead>
						{volist name="userCart" id="user_Cart"}
						<tr class="item">
							<td>{$user_Cart.goods.goods_code}</td>
							<td class="p-img">
								<a class="in_b" href="{:url('index/Goods/index',array('id'=>$user_Cart.goods.id))}">
									<img class="vm" alt="{$user_Cart.goods.goods_name}" width="40" src="/static/uploads/{$user_Cart.goods.og_thumb}">
								</a>
							</td>
							<td class="p-name">
								<h2> <a title="{$user_Cart.goods.goods_name}" href="{:url('index/Goods/index',array('id'=>$user_Cart.goods.id))}">{$user_Cart.goods.goods_name}</a> </h2>
							</td>
							<td class="p-price">
								<span class="price">&yen; {$user_Cart.goods.shop_price}</span>
							</td>
							<td class="p-quantity">
								{$user_Cart.number}
							</td>
							<td class="p-remove"></td>
						</tr>
						{/volist}
						<tr class="cart_toolbar">
							<td colspan="5">
								<div style="width: 200px;" class="control">
								</div>
							</td>

							<td class="total_box" colspan="6">
								<p>
									<label for="应付金额">总计</label> <span id="Jfinal" class="c_red total_price">¥<i>{$sum_price}</i></span>
								</p>
							</td>
						</tr>
						<tr class="cart_total">
							<td colspan="8">
								<a class="account" onclick="order()">下单</a>
							</td>
						</tr>
						</tbody>
					</table>
				</div>
			</div>
		</div>

	</div>
</div>
{include file='index@public/footer'}
<script>
	function order() {
		var address_is = $("#address_is").val();
		if(address_is == 0){
		    layer.alert('请添加收获地址后再尝试下单',function () {
                location.href = "{:url('user/user/addAddress')}";
            });
		    return;
		}
		// 获取手机地址
		var addressID = $("input[name='address']:checked").val();
		// 货运方式
		var shipping_name = $("#shipping_name").val();
        $.ajax({
            url:"{:url('user/order/order')}",
            type:"POST",
            dataType:"json",
            data:{
                addressID:addressID,
                shipping_name:shipping_name
            },
            success:function (res) {
                if(res.code == -1){
                    layer.alert(res.msg,function () {
                        location.href = "{:url('user/user/addAddress')}";
                    })
				}else if(res.code == 1){
                    layer.alert('下单成功！请支付',function () {
                        var url = "/show_order/"+res.orderId+".html";
                        location.href = url;
                    })
				}else if(res.code == -2){
                    layer.alert(res.msg,function () {
                        location.href = "/";
                    })
				}else if(res.code == -5){
                    layer.alert(res.msg)
					return ;
				}
            }
        });

    }
	
</script>